//
//  NRWCarDetailVC.m
//  NRWMall
//
//  Created by 张记 on 2018/5/22.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWCarDetailVC.h"
#import "NRWCarHeaderView.h"
#import "NRWCarDetailCell.h"
#import "NRWCarDetailNameCell.h"
#import "NRWCarDetailFooter.h"
#import "NRWCarDetailBaseInfoCell.h"
#import "NRWCarDetailMoreInfoCell.h"
#import "NRWCarDetailSellerInfoCell.h"
#import "NRWCarAuthCell.h"
#import "NRWCarDetailictureCell.h"
#import "NRWCarDetailLiveCarCell.h"
#import "NRWCarPopTool.h"
#import "NRWCarConfInfoVC.h"
#import "NRWCollectCarButton.h"
#import "NRWCarDetailApi.h"
#import "NRWCarDetailModel.h"
#import "NRWYouMayAlsoLikeApi.h"
#import "NRWBuyCarListDataModel.h"
#import "NRWLookCollectionStateApi.h"
#import "NRWCarCollectionApi.h"
#import "NRWCarCancelCollectionApi.h"
#import "NRWGetShopInfoApi.h"
#import "NRWShopInfoModel.h"
#import "FMDBInfo.h"
#import "NRWCarShareTool.h"
#import "WXApi.h"


@interface NRWCarDetailVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionview;
@property (nonatomic, assign) BOOL isSelected;
@property (nonatomic, assign) BOOL isNRWAuth;//是否是启辕认证
@property (nonatomic, assign) NSInteger tagB;
@property (nonatomic, strong) NRWCollectCarButton *collectBtn;
@property (nonatomic, assign) BOOL isCollect;
@property (nonatomic, strong) NRWCarDetailApi *carDetailApi;
@property (nonatomic, strong) NRWCarDetailModel *carDetailModel;
@property (nonatomic, strong) NSMutableArray *imageArray;
@property (nonatomic, copy) NSString *firstImageUrl;
@property (nonatomic, strong) NSArray *baseInfoArray;
@property (nonatomic, strong) NRWYouMayAlsoLikeApi *youLikeApi;
@property (nonatomic, strong) NRWBuyCarListDataModel *carListModel;
@property (nonatomic, strong) NRWLookCollectionStateApi *collectionStateApi;
@property (nonatomic, strong) NRWCarCollectionApi *collectionApi;
@property (nonatomic, strong) NRWCarCancelCollectionApi *cancelCollectionApi;
@property (nonatomic, strong) NRWGetShopInfoApi *getShopInfoApi;
@property (nonatomic, strong) NRWShopInfoModel *shopInfoModel;
@property (nonatomic, assign) BOOL isDriveCard;
@property (nonatomic, assign) BOOL isRegisterCard;
@property (nonatomic, strong) NRWUserInfoModel *userModel;
@property (nonatomic, strong) NSMutableArray *likeArray;

@end

@implementation NRWCarDetailVC
-(NRWCarDetailApi *)carDetailApi{
    if (!_carDetailApi) {
        _carDetailApi = [[NRWCarDetailApi alloc] init];
        _carDetailApi.delegate = self;
    }
    return _carDetailApi;
}
-(NRWCarDetailModel *)carDetailModel{
    if (!_carDetailModel) {
        _carDetailModel = [[NRWCarDetailModel alloc] init];
    }
    return _carDetailModel;
}

-(NSMutableArray *)imageArray{
    if (!_imageArray) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}
-(NRWYouMayAlsoLikeApi *)youLikeApi{
    if (!_youLikeApi) {
        _youLikeApi = [[NRWYouMayAlsoLikeApi alloc] init];
        _youLikeApi.delegate = self;
    }
    return _youLikeApi;
}
-(NRWBuyCarListDataModel *)carListModel{
    if (!_carListModel) {
        _carListModel = [[NRWBuyCarListDataModel alloc] init];
    }
    return _carListModel;
}
-(NRWLookCollectionStateApi *)collectionStateApi{
    if (!_collectionStateApi) {
        _collectionStateApi = [[NRWLookCollectionStateApi alloc] init];
        _collectionStateApi.delegate = self;
    }
    return _collectionStateApi;
}
-(NRWCarCollectionApi *)collectionApi{
    if (!_collectionApi) {
        _collectionApi = [[NRWCarCollectionApi alloc] init];
        _collectionApi.delegate = self;
    }
    return _collectionApi;
}
-(NRWCarCancelCollectionApi *)cancelCollectionApi{
    if (!_cancelCollectionApi) {
        _cancelCollectionApi = [[NRWCarCancelCollectionApi alloc] init];
        _cancelCollectionApi.delegate = self;
    }
    return _cancelCollectionApi;
}
-(NRWGetShopInfoApi *)getShopInfoApi{
    if (!_getShopInfoApi) {
        _getShopInfoApi = [[NRWGetShopInfoApi alloc] init];
        _getShopInfoApi.delegate = self;
    }
    return _getShopInfoApi;
}
-(NRWShopInfoModel *)shopInfoModel{
    if (!_shopInfoModel) {
        _shopInfoModel = [[NRWShopInfoModel alloc] init];
    }
    return _shopInfoModel;
}
-(NSMutableArray *)likeArray{
    if (!_likeArray ) {
        _likeArray = [[NSMutableArray alloc] init];
    }
    return _likeArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.userModel = [NRWUserInfoModel shared];
    self.isSelected = NO;
    [self.navigationView setLeftTitle:nil image:@"go_back"];
    if ([WXApi isWXAppInstalled]) {
        [self.navigationView setRightTitle:nil image:@"share_white"];
    }else{
        [self.navigationView setRightTitle:nil image:@""];
    }
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];//白色
    self.navigationView.backgroundColor = [UIColor clearColor];
    self.view.backgroundColor =[UIColor whiteColor];
    [SVProgressHUD show];
    self.carDetailApi.carId = self.collectionStateApi.carId = self.carId;
    [self.carDetailApi start];
    if (self.userModel.isLogin == YES) {
        [self.collectionStateApi start];
    }
    self.getShopInfoApi.marketId = self.thisCarModel.marketId;
    self.getShopInfoApi.shopId = self.thisCarModel.shopId;
    [self.getShopInfoApi start];
    [self Initcollectionview];
    [self.navigationView addSubview:self.collectBtn];
    self.baseInfoArray = @[@"表显里程",@"上牌日期",@"城市",@"过户次数",@"变速箱",@"排量",@"外观颜色",@"内饰颜色",@"使用性质",@"交强险到期日期",@"商业险到期日期",@"车身类型",@"vin(车架号)",@"行驶证",@"登记证",@"保养记录",@"",@""];
    [self lookOverCaching];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessful:) name:userLoginSuccess object:nil];

}

-(void)loginSuccessful:(NSNotification *)nofit{
    if ([nofit.object isEqualToString:kCarDetailCollect]) {
        [self.collectionStateApi start];
    }
    
}
-(void)lookOverCaching{
    
    [[FMDBInfo sharedDataBase] addCarList:self.thisCarModel];
    NSMutableArray *arraya = [[FMDBInfo sharedDataBase] getAllCarLsit];
    if (arraya.count > 50) {
        Result *res = arraya[0];
        [[FMDBInfo sharedDataBase]deleteCarList:res];
    }
}

-(NRWCollectCarButton *)collectBtn{
    if (!_collectBtn) {
        _collectBtn = [[NRWCollectCarButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH() - 102, getNavHeight() - 35, 25, 25) collectImage:[UIImage imageNamed:@"collect_yellow"] unCollectImage:[UIImage imageNamed:@"collect_white"]];
        kSelfWeak;
        [_collectBtn setClickHandler:^(NRWCollectCarButton *collectButton) {
              
                if (collectButton.isSelected) {
                    weakSelf.collectionApi.carId = weakSelf.carId;
                    [weakSelf.collectionApi start];
                }else{
                    weakSelf.cancelCollectionApi.carId = weakSelf.carId;
                    [weakSelf.cancelCollectionApi start];
                }
                weakSelf.isCollect = collectButton.isSelected;
                
           
        }];

    }
    return _collectBtn;
}
-(void)Initcollectionview{
    
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//    layout.minimumLineSpacing      = 0;
//    layout.minimumInteritemSpacing = 0;
    _collectionview = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH(), SCREEN_HEIGHT()) collectionViewLayout:layout];
    [self.collectionview registerClass:[NRWCarDetailCell class] forCellWithReuseIdentifier:@"NRWCarDetailCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"NRWCarHeaderView"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailFooter" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"NRWCarDetailFooter"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailNameCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailNameCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailBaseInfoCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailBaseInfoCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailMoreInfoCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailMoreInfoCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailSellerInfoCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailSellerInfoCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarAuthCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarAuthCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailictureCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailictureCell"];
    [_collectionview registerNib:[UINib nibWithNibName:@"NRWCarDetailLiveCarCell" bundle:nil] forCellWithReuseIdentifier:@"NRWCarDetailLiveCarCell"];
    
    [self.collectionview registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    _collectionview.backgroundColor = backColor();
    if (@available(iOS 11.0, *)) {
        _collectionview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    [self.view addSubview:_collectionview];
    [self.view bringSubviewToFront:self.navigationView];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 7;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }else if (section == 1){
        if (self.isSelected == NO) {
            return 6;
        }
        return self.baseInfoArray.count;
    }else if (section == 2){
        return 1;
    }else if (section == 3){
        return 3;
    }else if (section == 4){
        return 1;
    }else if (section == 5){
        return self.imageArray.count;
    }else if (section == 6){
        return self.likeArray.count;
    }
    return 4;
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    NSArray *titles = @[@"",@"基本信息",@"",@"卖家信息",@"启辕认证",@"图片信息",@""];
    if (kind == UICollectionElementKindSectionFooter) {
        
        NRWCarDetailFooter *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"NRWCarDetailFooter" forIndexPath:indexPath];
        if (self.isSelected == YES) {
       
            CGAffineTransform transform= CGAffineTransformMakeRotation(M_PI);
            footerView.iconImage.transform = transform;
        }else{
            CGAffineTransform transform= CGAffineTransformMakeRotation(M_PI * 2);
            footerView.iconImage.transform = transform;
        }
        if (footerView.gestureRecognizers == nil) {
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerViewClickedAction:)];
            [footerView addGestureRecognizer:tap];
        }
            return footerView;
       
    }else{
      
        NRWCarHeaderView *headerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"NRWCarHeaderView" forIndexPath:indexPath];
        headerview.subTitle = titles[indexPath.section];
        if (indexPath.section == 6) {
            headerview.lineOne.hidden = YES;
            headerview.lineTwo.hidden = headerview.lineThree.hidden = headerview.liveL.hidden = NO;
        }else{
            headerview.lineOne.hidden = NO;
            headerview.lineTwo.hidden = headerview.lineThree.hidden = headerview.liveL.hidden = YES;
        }
        return headerview;
    }
 
}
- (void) headerViewClickedAction:(UITapGestureRecognizer *)sender
{
    if (self.isSelected == NO) {
        self.isSelected = YES;
       
    }else{
        self.isSelected = NO;
      
    }
    [self.collectionview reloadData];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 ) {
        if (indexPath.row == 0) {
            NRWCarDetailCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailCell" forIndexPath:indexPath];
            Cell.imageUrl = self.firstImageUrl;
            Cell.isAuth = self.carDetailModel.result.carAuthState;
            return Cell;
        }else if (indexPath.row == 1){
            NRWCarDetailNameCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailNameCell" forIndexPath:indexPath];
            Cell.carModel = self.carDetailModel.result;
            return Cell;
        }
    }else if (indexPath.section == 1){
        NRWCarDetailBaseInfoCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailBaseInfoCell" forIndexPath:indexPath];
        Cell.titleLabel.text = self.baseInfoArray[indexPath.row];
        Cell.index = indexPath;
        Cell.isDriveCard = self.isDriveCard;
        Cell.isRegisterCard = self.isRegisterCard;
        Cell.carModel = self.carDetailModel.result;
        return Cell;
    }else if (indexPath.section == 2){
        NRWCarDetailMoreInfoCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailMoreInfoCell" forIndexPath:indexPath];
        
        return Cell;
    }else if (indexPath.section == 3){
        NSArray *imageNames = @[@"seller_company",@"seller_adress",@"seller_phone"];
        NRWCarDetailSellerInfoCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailSellerInfoCell" forIndexPath:indexPath];
        Cell.icon.image = [UIImage imageNamed:imageNames[indexPath.row]];
        Cell.index = indexPath;
        if (self.shopInfoModel.result.count != 0) {
            Cell.shopModel = self.shopInfoModel.result[0];
        }
        Cell.mobile = self.carDetailModel.result.user.userMobile;
        return Cell;
        
    }else if (indexPath.section == 4){
        NRWCarAuthCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarAuthCell" forIndexPath:indexPath];
        kSelfWeak;
        Cell.block = ^(NSInteger tagB) {
            [weakSelf.collectionview reloadData];
            weakSelf.tagB = tagB;
        };
        return Cell;
    }else if (indexPath.section == 5){
        CarCarimages *imageModel = self.imageArray[indexPath.row];
        NRWCarDetailictureCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailictureCell" forIndexPath:indexPath];
        Cell.imageModel = imageModel;
        return Cell;
    }else if (indexPath.section == 6){
        Result *rt = self.likeArray[indexPath.row];
        NRWCarDetailLiveCarCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailLiveCarCell" forIndexPath:indexPath];
        Cell.carListModel = rt;
        return Cell;
        
        
    }
    NRWCarDetailCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NRWCarDetailCell" forIndexPath:indexPath];
    Cell.backgroundColor = [UIColor whiteColor];
    return Cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return CGSizeMake(SCREEN_WIDTH(), SCREEN_WIDTH() * 3/4);
        }else if (indexPath.row == 1){
            return CGSizeMake(SCREEN_WIDTH(), 110);
        }
    }else if (indexPath.section == 1){
        return CGSizeMake(SCREEN_WIDTH() / 3, 60);
    }else if (indexPath.section == 3){
        if (indexPath.row == 0) {
            return CGSizeMake(SCREEN_WIDTH(), 60);
        }else{
            return CGSizeMake(SCREEN_WIDTH(), 40);
        }
    }else if (indexPath.section == 4){
        if (self.isNRWAuth == YES) {
            if (self.tagB == 4) {
                return CGSizeMake(SCREEN_WIDTH(), 300);
            }else if (self.tagB == 2){
                return CGSizeMake(SCREEN_WIDTH(), 280);
            }else if (self.tagB == 3){
                return CGSizeMake(SCREEN_WIDTH(), 280);
            }else{
                return CGSizeMake(SCREEN_WIDTH(), 255);
            }
        }else{
              return CGSizeMake(SCREEN_WIDTH(), 0.001);
        }
    }else if (indexPath.section == 5){
        return CGSizeMake(SCREEN_WIDTH(), (SCREEN_WIDTH() - 32) *3/4 + 50);

    }else if (indexPath.section == 6){
        return CGSizeMake((SCREEN_WIDTH() - 5) / 2, 290);
    }
    return CGSizeMake(SCREEN_WIDTH(), 50);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 2 ) {
        return CGSizeMake(SCREEN_WIDTH(), 0.001);
    }else if (section == 4){
        if (self.isNRWAuth == YES) {
           return CGSizeMake(SCREEN_WIDTH(), 30);
        }else{
            return CGSizeMake(SCREEN_WIDTH(), 0.001);
        }
    }else if (section == 6){
        return CGSizeMake(SCREEN_WIDTH(), 40);
    }
    return CGSizeMake(SCREEN_WIDTH(), 30);

}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if (section == 1) {
        return CGSizeMake(SCREEN_WIDTH(), 35);
    }
    return CGSizeMake(SCREEN_WIDTH(), 0.001);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2) {
        NRWCarConfInfoVC *carConfInfoVC = [[NRWCarConfInfoVC alloc] init];
        carConfInfoVC.detailModel = self.carDetailModel;
        [self.navigationController pushViewController:carConfInfoVC animated:YES];
    }else if (indexPath.section == 6){
        Result *rt = self.likeArray[indexPath.row];
        NRWCarDetailVC *carDetailVC = [[NRWCarDetailVC alloc] init];
        carDetailVC.carId = rt.carId;
        carDetailVC.thisCarModel = rt;
        [self.navigationController pushViewController:carDetailVC animated:YES];
    }else if (indexPath.section == 3){
        if (indexPath.row == 2) {
            
            [self callPhoneWithPhoneNum:self.carDetailModel.result.user.userMobile];
        }
    }
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    if (section == 6) {
        return 5;
    }
    return 0;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    if (section == 6) {
        return 5;
    }
    return 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewDidDisappear:(BOOL)animated{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];//白色
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    UIColor *color = getColor(@"ffffff");
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY > 105) {
        CGFloat alpha = MIN(1, 1 - (SCREEN_WIDTH() / 2 - offsetY) / 105);
        self.navigationView.backgroundColor = [color colorWithAlphaComponent:alpha];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
        [self.navigationView setLeftTitle:nil image:@"nav_back"];
        [self.navigationView setRightTitle:@"" image:@"share_black"];
        if (self.isCollect == YES) {
            _collectBtn.collectImage = [UIImage imageNamed:@"collect_yellow"];
            _collectBtn.unCollectImageNO = [UIImage imageNamed:@"collect_black"];
        }else{
            _collectBtn.unCollectImage = [UIImage imageNamed:@"collect_black"];
        }
        [self.navigationView setTitle:@"车辆详情"];

    }else{
        self.navigationView.backgroundColor = [color colorWithAlphaComponent:0];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];//白色
        [self.navigationView setLeftTitle:nil image:@"go_back"];
        [self.navigationView setRightTitle:@"" image:@"share_white"];
        if (self.isCollect == YES) {
            _collectBtn.collectImage = [UIImage imageNamed:@"collect_yellow"];
            _collectBtn.unCollectImageNO = [UIImage imageNamed:@"collect_white"];

        }else{
            _collectBtn.unCollectImage = [UIImage imageNamed:@"collect_white"];
        }
        [self.navigationView setTitle:@""];

    }
    
}

#pragma mark 数据请求
- (void)requestFinished:(__kindof YTKBaseRequest *)request {
    if (request == self.carDetailApi) {
        self.carDetailModel = [NRWCarDetailModel mj_objectWithKeyValues:request.responseObject];
        if (self.carDetailModel.code == 1) {
            for (CarCarimages *imageModel in self.carDetailModel.result.carImages) {
                if ([imageModel.imageKey isEqualToString:kImageLeft_anterior]) {
                    self.firstImageUrl = [NSString stringWithFormat:@"%@%@",imageApi(),imageModel.imageUrl];
                    [self.imageArray addObject:imageModel];
                }else if ([imageModel.imageKey isEqualToString:kImageVehicle_license]){
                    if (isEmptyString(imageModel.imageUrl) == NO) {
                        self.isDriveCard = YES;
                    }
                }else if ([imageModel.imageKey isEqualToString:kImageRegistration_license]){
                    if (isEmptyString(imageModel.imageUrl) == NO) {
                        self.isRegisterCard = YES;
                    }
                }else if ([imageModel.imageKey isEqualToString:kImageVin]){
                    
                }else if ([imageModel.imageKey isEqualToString:kImageInsurance]){
                    
                }else{
                    [self.imageArray addObject:imageModel];
                }
            }
            self.youLikeApi.marketId = self.carDetailModel.result.marketId;
            self.youLikeApi.carPrice = self.carDetailModel.result.carRetailPrice;
            [self.youLikeApi start];
        }else{
            [NRWMessageHUD showMessage:self.carDetailModel.msg forTime:2.0 withRemindId:remindFail];
        }
        if (self.carDetailModel.result.carAuthState == 10) {
            self.isNRWAuth = YES;
        }else{
            self.isNRWAuth = NO;
        }
        [self.collectionview reloadData];

    }else if (request == self.youLikeApi){
        self.carListModel = [NRWBuyCarListDataModel mj_objectWithKeyValues:request.responseObject];
        for (Result *model in self.carListModel.result) {
            if ([model.carId isEqualToString:self.carDetailModel.result.carId]) {
            }else{
                [self.likeArray addObject:model];
            }
        }
        
        [self.collectionview reloadData];

    }else if (request == self.collectionStateApi){
        
        if ([request.responseObject[@"code"] isEqual:@1]) {
         
            if ([request.responseObject[@"result"][@"favoriteState"] isEqual:@1]) {
                self.collectBtn.isSelected = self.isCollect = YES;
            }else{
                  self.collectBtn.isSelected = self.isCollect = NO;
            }
            
        }
        
    }else if (request == self.collectionApi){
        
        if ([request.responseObject[@"code"] isEqual:@1]) {
            [NRWMessageHUD showMessage:@"收藏成功" forTime:2.0 withRemindId:remindSuccess];
        }else{
            [NRWMessageHUD showMessage:@"收藏失败" forTime:2.0 withRemindId:remindFail];
        }
        
    }else if (request == self.cancelCollectionApi){
        if ([request.responseObject[@"code"] isEqual:@1]) {
            [NRWMessageHUD showMessage:@"取消收藏成功" forTime:2.0 withRemindId:remindSuccess];
        }else{
            [NRWMessageHUD showMessage:@"取消收藏失败" forTime:2.0 withRemindId:remindFail];
        }
    }else if (request == self.getShopInfoApi){
        self.shopInfoModel = [NRWShopInfoModel mj_objectWithKeyValues:request.responseObject];
    
    }
  
    [SVProgressHUD dismiss];
    
}

- (void)requestFailed:(__kindof YTKBaseRequest *)request {
    [SVProgressHUD dismiss];
//    [NRWMessageHUD showMessage:@"请求失败" forTime:2.0 withRemindId:remindFail];
    
}
-(void)navigationViewRightItemDidClick{
    if ([WXApi isWXAppInstalled]) {
        //显示弹出框列表选择
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"分享"
                                                                       message:nil
                                                                preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                             handler:^(UIAlertAction * action) {
                                                             

                                                             }];
        UIAlertAction* wxcircle = [UIAlertAction actionWithTitle:@"朋友圈" style:UIAlertActionStyleDestructive
                                                             handler:^(UIAlertAction * action) {
                                                                 [NRWCarShareTool shareCarDetailWithCarDetailModel:self.carDetailModel shareType:ShareTypeWXCircle];
                                                             }];
        UIAlertAction* weChat = [UIAlertAction actionWithTitle:@"微信" style:UIAlertActionStyleDestructive
                                                         handler:^(UIAlertAction * action) {
                                                             [NRWCarShareTool shareCarDetailWithCarDetailModel:self.carDetailModel shareType:ShareTypeWeiXin];
                                                         }];
        [alert addAction:weChat];
        [alert addAction:wxcircle];
        [alert addAction:cancel];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

-(void)dealloc{
    
}
@end
